package com.xpgk.mvc.shopProfitQuery;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.bcost.SbPay;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.productSales.ProductSales;
import com.xpgk.mvc.scallVisit.ScallVisit;
import com.xpgk.mvc.statistic.daySales.DaySalesXLS;

public class ShopProfitQueryController extends  BaseController{
	
	public  void   index(){
		setAttr("curOrgan", Organization.dao.findById(getCUserOrganIds()));
		render("shopProfitQuery.html");
	};
	
	/*
	 * 查询利润表
	 */
	public void queryPrice(){
		String organIds = getPara("selOrganIds");
		String minTime = getPara("minTime");
		String maxTime = getPara("maxTime");
		List<Record> result = new ShopProfitQueryService().queryPrice(organIds, minTime, maxTime);
		renderJson(result);
	}
	/*
	 * 查询结果导出
	 */
	public void excel(){
		String organIds = getPara("selOrganIds");
		String minTime = getPara("minTime");
		String maxTime = getPara("maxTime");

		Organization organ=Organization.dao.findById(organIds);//门店
		String organizationName = organIds.equals("")?"":("门店："+organ.getStr(Organization.column_name)+"，");
		String minTimeSearch = minTime.equals("")?"":("最早日期："+minTime+"，");
		String maxTimeSearch = maxTime.equals("")?"":("最早日期："+maxTime+"，");
		
		
		String search = organIds.equals("")?"":(organizationName+minTimeSearch+maxTimeSearch);
		
		List<Record> result = new ShopProfitQueryService().queryPrice(organIds, minTime, maxTime);
		Integer resultsize = new ShopProfitQueryService().resultsize(organIds, minTime, maxTime);
		Integer chargesize = new ShopProfitQueryService().chargesize(organIds, minTime, maxTime);
		render(new ShopProfitQueryXLS(result, "门店利润表",resultsize,chargesize,search));
	}
};